//
//  SNVisitorView.m
//  SinaVboc
//
//  Created by V on 29/11/2016.
//  Copyright © 2016 仁忄. All rights reserved.
//

#import "SNVisitorView.h"


@interface SNVisitorView ()

@property (nonatomic, strong) UIImageView *homeImageView;
@property (nonatomic, strong) UIImageView *circleImageView;
@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) UIButton *loginButton;
@property (nonatomic, strong) UIButton *registerButton;

@end

@implementation SNVisitorView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
        [self circleAnimation];
    }
    
    return  self;
}


- (void)circleAnimation {
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    anim.duration = 20;
    anim.repeatCount = INT32_MAX;
    anim.toValue = @(M_PI * 2);
    anim.removedOnCompletion = NO;
    
    [_circleImageView.layer addAnimation:anim forKey:nil];
}



- (void)loginButtonDidClicked:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(userWillLogin)]) {
        
        [self.delegate userWillLogin];
    }
    
}
- (void)registerButtonDidClicked:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(userWillRegister)]) {
        
        [self.delegate userWillRegister];
    }
}




- (void)setupUI {
    
    [self.loginButton addTarget:self action:@selector(loginButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.registerButton addTarget:self action:@selector(registerButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    self.backgroundColor = [UIColor colorWithWhite:237.0 / 255.0 alpha:1];
    
    [self addSubview:self.circleImageView];
    [self addSubview:self.coverImageView];
    [self addSubview:self.homeImageView];
    [self addSubview:self.tipLabel];
    [self addSubview:self.loginButton];
    [self addSubview:self.registerButton];
    
    [_circleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-100);
    }];
    
    [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_circleImageView);
    }];
    
    [_homeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_coverImageView);
    }];
    
    [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_homeImageView);
        make.top.equalTo(_homeImageView.mas_bottom).offset(20);
    }];
    
    [_loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.left.equalTo(_tipLabel.mas_left);
        make.top.equalTo(_tipLabel.mas_bottom).offset(10);
    }];
    
    [_registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(_loginButton);
        make.right.equalTo(_tipLabel.mas_right);
        make.top.equalTo(_loginButton);
    }];
}



#pragma mark - 懒加载控件
- (UIButton *)loginButton {
    
    if (!_loginButton) {
        _loginButton = [[UIButton alloc] initWithTitle:@"登录" titleSize:15 titleColor:[UIColor orangeColor]];
        
        [_loginButton setBackgroundImage:[UIImage imageNamed:@"common_button_white"] forState:UIControlStateNormal];
    }
    return _loginButton;
}

- (UIButton *)registerButton {
    
    if (!_registerButton) {
        _registerButton = [[UIButton alloc] initWithTitle:@"注册" titleSize:15 titleColor:[UIColor orangeColor]];
        
        [_registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white"] forState:UIControlStateNormal];
    }
    return _registerButton;
}

- (UILabel *)tipLabel {
    
    if (!_tipLabel) {
        _tipLabel  = [[UILabel alloc] initWithTitle:@"关注一些人,回到这里看看有什么惊喜" titleSize:15 titleColor:[UIColor grayColor]];
        
        _tipLabel.numberOfLines = 0;
        _tipLabel.textAlignment = NSTextAlignmentCenter;
        _tipLabel.preferredMaxLayoutWidth = kScreenWidth / 1.8;
    }
    return  _tipLabel;
}

- (UIImageView *)homeImageView {
    
    if (!_homeImageView) {
        _homeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeImageView;
}

- (UIImageView *)circleImageView {
    
    if (!_circleImageView) {
        _circleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _circleImageView;
}

- (UIImageView *)coverImageView {
    
    if (!_coverImageView) {
        _coverImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    return _coverImageView;
}





@end



















































